package database;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;


public class MyConnection{
	
	private static MyConnection myconn=null;
	Connection con=null;
	public static MyConnection getInstance()
	{
		if(myconn==null)
		{
			myconn=new MyConnection();
		}
		return myconn;
	}
	public MyConnection()
	{
		
	}
	public static Connection getConnection() throws Exception
	{
		InitialContext initialContext = new InitialContext();
		Context context = (Context) initialContext.lookup("java:comp/env");
		DataSource ds = (DataSource) context.lookup("connpool");
		Connection connection;
		connection = ds.getConnection();
		return connection;
	}
	
	public static void close(Connection o)
	{
		try{
		if(o!=null) {
				o.close();
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	public static void close(Statement o)
	{
		try{
			if(o!=null) {
				o.close();
			}
			}catch(Exception ex)
			{
				ex.printStackTrace();
			}
	}
	public static void close(ResultSet o)
	{
		try{
			if(o!=null) {
				o.close();
			}
			}catch(Exception ex)
			{
				ex.printStackTrace();
			}
	}
}
